package org.example.lost.controller;

import com.auth0.jwt.impl.PublicClaims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.example.domain.PageInfoDTO;
import org.example.domain.Result;
import org.example.lost.entity.LostInfo;
import org.example.lost.entity.dto.KindDTO;
import org.example.lost.entity.vo.LostInfoVO;
import org.example.lost.service.KindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物品分类的功能
 * 1、查询分类的全部信息
 * 2、新增分类
 * 3、删除分类
 * @Author hxy
 * @Date 2021/3/24 20:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/core")
@Api(tags = "分类")
//@CrossOrigin(allowCredentials = "true",allowedHeaders="*")
public class KindController {
    @Autowired
    KindService kindService;


    @GetMapping(value = "/kinds")
    @ApiOperation("列表查询分类")
    public Result<List<KindDTO>> getList(){
        List<KindDTO> list = kindService.getList();
        if(list == null){
            return Result.fail("无分类信息");
        }
        return Result.success(list);
    }


    @PostMapping("/kind")
    @ApiOperation("新增分类")
    public Result<String> addKind(@RequestBody KindDTO kindDTO){
        int result = kindService.addKind(kindDTO);
        if(result == 1){
            return Result.success("新增分类成功");
        }
        return Result.fail("新增分类失败");
    }


    @DeleteMapping("/kind/{kindId}")
    @ApiOperation("删除分类")
    public Result<String> delete(@PathVariable(name = "kindId") @ApiParam(name = "kindId",value = "分类id") String kindId){
        int result = kindService.delete(kindId);
        if(result == 1){
            return Result.success("删除类成功");
        }
        return Result.fail("删除分类失败");
    }
}
